package com.spring.springboot.sys.core.constant;

import com.spring.springboot.sys.core.config.MinioProperties;
import com.spring.springboot.sys.core.config.SendMessageProperties;
import com.spring.springboot.sys.util.RedisUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author 宋义州
 * @date 2022-07-25  22:54
 * @description 系统参数配置查询
 */
@Component
public class ConstantsContext {

    @Resource
    private RedisUtils redis;

    private static RedisUtils redisUtils;

    @PostConstruct
    public void initRedisUtils() {
        redisUtils = redis;
    }

    /**
     * 获取minio文件上传服务配置
     *
     * @return MinioProperties
     */
    public static MinioProperties getMinioProperties() {
        String minioEndpoint = (String) redisUtils.get(BusinessConstant.Minio.ENDPOINT);
        String minioAccessKey = (String) redisUtils.get(BusinessConstant.Minio.ACCESS_KEY);
        String minioSecretKey = (String) redisUtils.get(BusinessConstant.Minio.SECRET_KEY);
        String minioNginxHost = (String) redisUtils.get(BusinessConstant.Minio.NGINX_HOST);
        return new MinioProperties(minioEndpoint, minioAccessKey, minioSecretKey, minioNginxHost);
    }

    /**
     * 获取腾讯云短信服务配置
     *
     * @return SendMessageProperties
     */
    public static SendMessageProperties getSendMessageProperties() {
        String msgSecretId = (String) redisUtils.get(BusinessConstant.SendMessage.MSG_SECRET_ID);
        String msgSecretKey = (String) redisUtils.get(BusinessConstant.SendMessage.MSG_SECRET_KEY);
        String msgSdkAppId = (String) redisUtils.get(BusinessConstant.SendMessage.MSG_SDK_APP_ID);
        String msgAppKey = (String) redisUtils.get(BusinessConstant.SendMessage.MSG_APP_KEY);
        String msgSignName = (String) redisUtils.get(BusinessConstant.SendMessage.MSG_SIGN_NAME);
        String msgTemplateId = (String) redisUtils.get(BusinessConstant.SendMessage.MSG_TEMPLATE_ID);
        return new SendMessageProperties(msgSecretId, msgSecretKey, msgSdkAppId, msgAppKey, msgSignName, msgTemplateId);
    }

}
